﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.Company
{
    public partial class CompanyList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindOwnCompanyList();
            }
        }

        #region 加载我创建的小组列表
        private void BindOwnCompanyList()
        {
            Users uinfo = UserBase.GetCurrentUser();
            CompanysHelper chelper = new CompanysHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "OwnerUserID", uinfo.ID);
            c.Add(CriteriaType.Equals, "Flag", 0);
            DataTable dt = chelper.QueryCompanysBySearchToTable(c, null, 0, 0, null);

            if (dt != null && dt.Rows.Count > 0)
            {
                lblOwnCompany.Visible = false;
                rptOwnCompanyList.DataSource = dt;
                rptOwnCompanyList.DataBind();
            }
            else
            {
                lblOwnCompany.Visible = true;
                rptOwnCompanyList.Visible = false;
                lblOwnCompany.Text = "没有创建的小组，<a href=\"CompanyAdd.aspx\">马上创建</a>";
            }
        }
        #endregion

        #region 创建的小组列表事件
        protected void rptOwnCompanyList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            HiddenField hidID = (HiddenField)e.Item.FindControl("hidID");
            string companyid = hidID.Value;
            if (e.CommandName == "edit")
            {
                Response.Redirect("CompanyEdit.aspx?id="+companyid);
            }
            else if (e.CommandName == "userlist")
            {
                Response.Redirect("UserList.aspx?id=" + companyid);
            }
            else if (e.CommandName == "notice")
            {
                Response.Redirect("CompanyNoticeAdd.aspx?id=" + companyid);
            }
            else if (e.CommandName == "bloglist")
            {
                Response.Redirect("UserCompanyBlogList.aspx?id=" + companyid);
            }
        }
        #endregion
    }
}